﻿namespace EFMLEditor
{
    using System;
    using System.Linq;
    using System.Windows.Forms;

    using EFML_Runtime.Internal;

    public class StringsPage : UserControl
    {
        /// <summary>
        /// 	Erforderliche Designervariable.
        /// </summary>
        private readonly System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 	Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing"> True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. </param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Komponenten-Designer generierter Code

        /// <summary>
        /// 	Erforderliche Methode für die Designerunterstützung. 
        /// 	Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // listBox1
            // 
            this.listBox1.FormattingEnabled = true;
            this.listBox1.Location = new System.Drawing.Point(4, 4);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new System.Drawing.Size(159, 264);
            this.listBox1.TabIndex = 0;
            this.listBox1.SelectedIndexChanged += this.listBox1_SelectedIndexChanged;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(170, 4);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(38, 13);
            this.label1.TabIndex = 1;
            this.label1.Text = "Name:";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(170, 40);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(37, 13);
            this.label2.TabIndex = 2;
            this.label2.Text = "Value:";
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(215, 4);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(338, 20);
            this.textBox1.TabIndex = 3;
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(215, 37);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(338, 20);
            this.textBox2.TabIndex = 4;
            // 
            // StringsPage
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.listBox1);
            this.Name = "StringsPage";
            this.Size = new System.Drawing.Size(581, 277);
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        #endregion

        private ListBox listBox1;

        private Label label1;

        private Label label2;

        private TextBox textBox1;

        private TextBox textBox2;

        private readonly Document d;

        private readonly StringParser sp;

        public StringsPage(Document d)
        {
            this.d = d;
            this.InitializeComponent();

            this.sp = new StringParser();
            this.sp.Load(d.Value);
            foreach (var s in this.sp.Strings)
            {
                this.listBox1.Items.Add(s.Key);
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (var document in this.sp.Strings.Where(document => document.Key == this.listBox1.SelectedItem.ToString()))
            {
                this.textBox1.Text = document.Key;
                this.textBox2.Text = document.Value;
            }
        }
    }
}